

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/fluid.png">
  <link rel="icon" href="/img/fluid.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="dayu">
  <meta name="keywords" content="">
  
    <meta name="description" content="SQL笔记SQL SELECT 语句从 “Websites” 表中选取 “name” 和 “country” 列： 1SELECT name,country FROM Websites;  从 “Websites” 表中选取所有列： 1ELECT * FROM Websites;  SQL SELECT DISTINCT 语句仅从 “Websites” 表的 “country” 列中选取唯一不同的">
<meta property="og:type" content="article">
<meta property="og:title" content="sql">
<meta property="og:url" content="http://example.com/2023/02/25/sql/index.html">
<meta property="og:site_name" content="Dayu">
<meta property="og:description" content="SQL笔记SQL SELECT 语句从 “Websites” 表中选取 “name” 和 “country” 列： 1SELECT name,country FROM Websites;  从 “Websites” 表中选取所有列： 1ELECT * FROM Websites;  SQL SELECT DISTINCT 语句仅从 “Websites” 表的 “country” 列中选取唯一不同的">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2023-02-24T16:44:02.000Z">
<meta property="article:modified_time" content="2023-09-05T13:21:06.297Z">
<meta property="article:author" content="dayu">
<meta property="article:tag" content="sql">
<meta name="twitter:card" content="summary_large_image">
  
  
  
  <title>sql - Dayu</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/css/highlight-dark.css" />
  




  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"example.com","root":"/","version":"1.9.3","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"follow_dnt":true,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml"};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
  


  
<meta name="generator" content="Hexo 5.4.2"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>dayu</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              &nbsp;<i class="iconfont icon-search"></i>&nbsp;
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/img/default.png') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="sql"></span>
          
        </div>

        
          
  <div class="mt-3">
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2023-02-25 00:44" pubdate>
          2023年2月25日 凌晨
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          5.4k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          46 分钟
        
      </span>
    

    
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">sql</h1>
            
            
              <div class="markdown-body">
                
                <h1 id="SQL笔记"><a href="#SQL笔记" class="headerlink" title="SQL笔记"></a>SQL笔记</h1><h2 id="SQL-SELECT-语句"><a href="#SQL-SELECT-语句" class="headerlink" title="SQL SELECT 语句"></a>SQL SELECT 语句</h2><p>从 “Websites” 表中选取 “name” 和 “country” 列：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">SELECT</span> name,country <span class="hljs-keyword">FROM</span> Websites;<br></code></pre></td></tr></table></figure>

<p>从 “Websites” 表中选取所有列：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs sql">ELECT <span class="hljs-operator">*</span> <span class="hljs-keyword">FROM</span> Websites;<br></code></pre></td></tr></table></figure>

<h2 id="SQL-SELECT-DISTINCT-语句"><a href="#SQL-SELECT-DISTINCT-语句" class="headerlink" title="SQL SELECT DISTINCT 语句"></a>SQL SELECT DISTINCT 语句</h2><p>仅从 “Websites” 表的 “country” 列中选取唯一不同的值，也就是去掉 “country” 列重复值：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">DISTINCT</span> country <span class="hljs-keyword">FROM</span> Websites;<br></code></pre></td></tr></table></figure>

<h2 id="SQL-WHERE-子句"><a href="#SQL-WHERE-子句" class="headerlink" title="SQL WHERE 子句"></a>SQL WHERE 子句</h2><p>从 “Websites” 表中选取国家为 “CN” 的所有网站：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">SELECT</span> <span class="hljs-operator">*</span> <span class="hljs-keyword">FROM</span> Websites <span class="hljs-keyword">WHERE</span> country<span class="hljs-operator">=</span><span class="hljs-string">&#x27;CN&#x27;</span>;<br></code></pre></td></tr></table></figure>

<p>如果是数值字段，请不要使用引号</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">SELECT</span> <span class="hljs-operator">*</span> <span class="hljs-keyword">FROM</span> Websites <span class="hljs-keyword">WHERE</span> id<span class="hljs-operator">=</span><span class="hljs-number">1</span>;<br></code></pre></td></tr></table></figure>

<h2 id="SQL-AND-amp-OR-运算符"><a href="#SQL-AND-amp-OR-运算符" class="headerlink" title="SQL AND &amp; OR 运算符"></a>SQL AND &amp; OR 运算符</h2><p>从 “Websites” 表中选取国家为 “CN” 且alexa排名大于 “50” 的所有网站：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">select</span> <span class="hljs-operator">*</span> <span class="hljs-keyword">from</span> websites<br><span class="hljs-keyword">where</span> country<span class="hljs-operator">=</span><span class="hljs-string">&#x27;CN&#x27;</span><br><span class="hljs-keyword">and</span> alexa<span class="hljs-operator">&gt;</span><span class="hljs-number">50</span><br></code></pre></td></tr></table></figure>

<p>从 “Websites” 表中选取国家为 “USA” 或者 “CN” 的所有客户：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">select</span> <span class="hljs-operator">*</span> <span class="hljs-keyword">from</span> websites<br><span class="hljs-keyword">where</span> country<span class="hljs-operator">=</span><span class="hljs-string">&#x27;USA&#x27;</span><br><span class="hljs-keyword">or</span> country<span class="hljs-operator">=</span><span class="hljs-string">&#x27;CN&#x27;</span><br></code></pre></td></tr></table></figure>

<p>从 “Websites” 表中选取 alexa 排名大于 “15” 且国家为 “CN” 或 “USA” 的所有网站：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">select</span> <span class="hljs-operator">*</span> <span class="hljs-keyword">from</span> websites<br><span class="hljs-keyword">where</span> alexa <span class="hljs-operator">&gt;</span> <span class="hljs-number">15</span><br><span class="hljs-keyword">and</span>(country <span class="hljs-operator">=</span> <span class="hljs-string">&#x27;CN&#x27;</span> <span class="hljs-keyword">or</span> country <span class="hljs-operator">=</span> <span class="hljs-string">&#x27;USA&#x27;</span>)<br></code></pre></td></tr></table></figure>

<h2 id="SQL-ORDER-BY-关键字"><a href="#SQL-ORDER-BY-关键字" class="headerlink" title="SQL ORDER BY 关键字"></a>SQL ORDER BY 关键字</h2><p>从 “Websites” 表中选取所有网站，并按照 “alexa” 列排序：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">select</span> <span class="hljs-operator">*</span> <span class="hljs-keyword">from</span> websites<br><span class="hljs-keyword">order</span> <span class="hljs-keyword">by</span> alexa<br></code></pre></td></tr></table></figure>

<p>从 “Websites” 表中选取所有网站，并按照 “alexa” 列降序排序：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">select</span> <span class="hljs-operator">*</span> <span class="hljs-keyword">from</span> websites<br><span class="hljs-keyword">order</span> <span class="hljs-keyword">by</span> alexa <span class="hljs-keyword">desc</span><br></code></pre></td></tr></table></figure>

<p>从 “Websites” 表中选取所有网站，并按照 “country” 和 “alexa” 列排序：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">select</span> <span class="hljs-operator">*</span> <span class="hljs-keyword">from</span> websites<br><span class="hljs-keyword">order</span> <span class="hljs-keyword">by</span> country,alexa<br></code></pre></td></tr></table></figure>

<p>向 “Websites” 表中插入一个新行。</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">insert</span> <span class="hljs-keyword">into</span> websites(name,url,alexa,country)<br><span class="hljs-keyword">values</span> (<span class="hljs-string">&#x27;百度&#x27;</span>,<span class="hljs-string">&#x27;https://www.baidu.com&#x27;</span>,<span class="hljs-string">&#x27;4&#x27;</span>,<span class="hljs-string">&#x27;CN&#x27;</span>)<br></code></pre></td></tr></table></figure>

<p>插入一个新行，但是只在 “name”、”url” 和 “country” 列插入数据（id 字段会自动更新）：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">insert</span> <span class="hljs-keyword">into</span> websites(name,url,country)<br><span class="hljs-keyword">values</span> (<span class="hljs-string">&#x27;stackoverflow&#x27;</span>,<span class="hljs-string">&#x27;http://stackoverflow.com/&#x27;</span>,<span class="hljs-string">&#x27;IND&#x27;</span>)<br></code></pre></td></tr></table></figure>

<h2 id="SQL-UPDATE-语句"><a href="#SQL-UPDATE-语句" class="headerlink" title="SQL UPDATE 语句"></a>SQL UPDATE 语句</h2><p>把 “菜鸟教程” 的 alexa 排名更新为 5000，country 改为 中国。</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">UPDATE</span> websites<br><span class="hljs-keyword">SET</span> alexa<span class="hljs-operator">=</span><span class="hljs-string">&#x27;5000&#x27;</span>,country<span class="hljs-operator">=</span><span class="hljs-string">&#x27;中国&#x27;</span><br><span class="hljs-keyword">where</span> name<span class="hljs-operator">=</span><span class="hljs-string">&#x27;菜鸟教程&#x27;</span><br></code></pre></td></tr></table></figure>

<h3 id="Update-警告！"><a href="#Update-警告！" class="headerlink" title="Update 警告！"></a>Update 警告！</h3><p>在更新记录时要格外小心！在上面的实例中，如果我们省略了 WHERE 子句，如下所示：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">UPDATE</span> Websites<br><span class="hljs-keyword">SET</span> alexa<span class="hljs-operator">=</span><span class="hljs-string">&#x27;5000&#x27;</span>, country<span class="hljs-operator">=</span><span class="hljs-string">&#x27;USA&#x27;</span><br></code></pre></td></tr></table></figure>

<p>执行以上代码会将 Websites 表中所有数据的 alexa 改为 5000，country 改为 USA。</p>
<p>执行没有 WHERE 子句的 UPDATE 要慎重，再慎重。</p>
<h2 id="SQL-DELETE-语句"><a href="#SQL-DELETE-语句" class="headerlink" title="SQL DELETE 语句"></a>SQL DELETE 语句</h2><p>从 “Websites” 表中删除网站名为 “Facebook” 且国家为 USA 的网站。</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">DELETE</span> <span class="hljs-keyword">FROM</span> Websites<br><span class="hljs-keyword">WHERE</span> name<span class="hljs-operator">=</span><span class="hljs-string">&#x27;Facebook&#x27;</span> <span class="hljs-keyword">AND</span> country<span class="hljs-operator">=</span><span class="hljs-string">&#x27;USA&#x27;</span>;<br></code></pre></td></tr></table></figure>

<h3 id="删除所有数据"><a href="#删除所有数据" class="headerlink" title="删除所有数据"></a>删除所有数据</h3><p>您可以在不删除表的情况下，删除表中所有的行。这意味着表结构、属性、索引将保持不变：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">DELETE</span> <span class="hljs-keyword">FROM</span> table_name;<br></code></pre></td></tr></table></figure>

<h2 id="SQL-SELECT-TOP-LIMIT-ROWNUM-子句"><a href="#SQL-SELECT-TOP-LIMIT-ROWNUM-子句" class="headerlink" title="SQL SELECT TOP, LIMIT, ROWNUM 子句"></a>SQL SELECT TOP, LIMIT, ROWNUM 子句</h2><p>从 “Websites” 表中选取头两条记录：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">SELECT</span> <span class="hljs-operator">*</span> <span class="hljs-keyword">FROM</span> websites LIMIT <span class="hljs-number">2</span><br></code></pre></td></tr></table></figure>

<h2 id="SQL-LIKE-操作符"><a href="#SQL-LIKE-操作符" class="headerlink" title="SQL LIKE 操作符"></a>SQL LIKE 操作符</h2><p>选取 name 以字母 “G” 开始的所有客户：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">SELECT</span> <span class="hljs-operator">*</span> <span class="hljs-keyword">FROM</span> Websites<br><span class="hljs-keyword">WHERE</span> name <span class="hljs-keyword">LIKE</span> <span class="hljs-string">&#x27;G%&#x27;</span>;<br></code></pre></td></tr></table></figure>

<p>选取 name 以字母 “k” 结尾的所有客户：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">SELECT</span> <span class="hljs-operator">*</span> <span class="hljs-keyword">FROM</span> Websites<br><span class="hljs-keyword">WHERE</span> name <span class="hljs-keyword">LIKE</span> <span class="hljs-string">&#x27;%k&#x27;</span>;<br></code></pre></td></tr></table></figure>

<p>选取 name 包含模式 “oo” 的所有客户：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">SELECT</span> <span class="hljs-operator">*</span> <span class="hljs-keyword">FROM</span> Websites<br><span class="hljs-keyword">WHERE</span> name <span class="hljs-keyword">LIKE</span> <span class="hljs-string">&#x27;%oo%&#x27;</span>;<br></code></pre></td></tr></table></figure>

<p>选取 name 不包含模式 “oo” 的所有客户：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">SELECT</span> <span class="hljs-operator">*</span> <span class="hljs-keyword">FROM</span> Websites<br><span class="hljs-keyword">WHERE</span> name <span class="hljs-keyword">NOT</span> <span class="hljs-keyword">LIKE</span> <span class="hljs-string">&#x27;%oo%&#x27;</span>;<br></code></pre></td></tr></table></figure>

<h2 id="SQL-通配符"><a href="#SQL-通配符" class="headerlink" title="SQL 通配符"></a>SQL 通配符</h2><h3 id="使用-SQL-通配符"><a href="#使用-SQL-通配符" class="headerlink" title="使用 SQL % 通配符"></a>使用 SQL % 通配符</h3><p>选取 url 以字母 “https” 开始的所有网站：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">SELECT</span> <span class="hljs-operator">*</span> <span class="hljs-keyword">FROM</span> Websites<br><span class="hljs-keyword">WHERE</span> url <span class="hljs-keyword">LIKE</span> <span class="hljs-string">&#x27;https%&#x27;</span>;<br></code></pre></td></tr></table></figure>

<p>选取 url 包含模式 “oo” 的所有网站：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">SELECT</span> <span class="hljs-operator">*</span> <span class="hljs-keyword">FROM</span> Websites<br><span class="hljs-keyword">WHERE</span> url <span class="hljs-keyword">LIKE</span> <span class="hljs-string">&#x27;%oo%&#x27;</span>;<br></code></pre></td></tr></table></figure>

<p>选取 name 以一个任意字符开始，然后是 “oogle” 的所有客户：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">SELECT</span> <span class="hljs-operator">*</span> <span class="hljs-keyword">FROM</span> Websites<br><span class="hljs-keyword">WHERE</span> name <span class="hljs-keyword">LIKE</span> <span class="hljs-string">&#x27;_oogle&#x27;</span>;<br></code></pre></td></tr></table></figure>

<p>选取 name 以 “G” 开始，然后是一个任意字符，然后是 “o”，然后是一个任意字符，然后是 “le” 的所有网站：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">SELECT</span> <span class="hljs-operator">*</span> <span class="hljs-keyword">FROM</span> Websites<br><span class="hljs-keyword">WHERE</span> name <span class="hljs-keyword">LIKE</span> <span class="hljs-string">&#x27;G_o_le&#x27;</span>;<br></code></pre></td></tr></table></figure>

<h3 id="使用-SQL-charlist-通配符"><a href="#使用-SQL-charlist-通配符" class="headerlink" title="使用 SQL [charlist] 通配符"></a>使用 SQL [charlist] 通配符</h3><p>选取 name 以 “G”、”F” 或 “s” 开始的所有网站：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">SELECT</span> <span class="hljs-operator">*</span> <span class="hljs-keyword">FROM</span> Websites<br><span class="hljs-keyword">WHERE</span> name REGEXP <span class="hljs-string">&#x27;^[GFs]&#x27;</span>;<br></code></pre></td></tr></table></figure>

<p>选取 name 以 A 到 H 字母开头的网站：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">SELECT</span> <span class="hljs-operator">*</span> <span class="hljs-keyword">FROM</span> Websites<br><span class="hljs-keyword">WHERE</span> name REGEXP <span class="hljs-string">&#x27;^[A-H]&#x27;</span>;<br></code></pre></td></tr></table></figure>

<p>选取 name 不以 A 到 H 字母开头的网站：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">SELECT</span> <span class="hljs-operator">*</span> <span class="hljs-keyword">FROM</span> Websites<br><span class="hljs-keyword">WHERE</span> name REGEXP <span class="hljs-string">&#x27;^[^A-H]&#x27;</span>;<br></code></pre></td></tr></table></figure>

<h2 id="SQL-IN-操作符"><a href="#SQL-IN-操作符" class="headerlink" title="SQL IN 操作符"></a>SQL IN 操作符</h2><p>选取 name 为 “Google” 或 “菜鸟教程” 的所有网站：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">SELECT</span> <span class="hljs-operator">*</span> <span class="hljs-keyword">FROM</span> Websites<br><span class="hljs-keyword">WHERE</span> name <span class="hljs-keyword">IN</span> (<span class="hljs-string">&#x27;Google&#x27;</span>,<span class="hljs-string">&#x27;菜鸟教程&#x27;</span>);<br></code></pre></td></tr></table></figure>

<h2 id="SQL-BETWEEN-操作符"><a href="#SQL-BETWEEN-操作符" class="headerlink" title="SQL BETWEEN 操作符"></a>SQL BETWEEN 操作符</h2><p>选取 alexa 介于 1 和 20 之间的所有网站：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">SELECT</span> <span class="hljs-operator">*</span> <span class="hljs-keyword">FROM</span> Websites<br><span class="hljs-keyword">WHERE</span> alexa <span class="hljs-keyword">BETWEEN</span> <span class="hljs-number">1</span> <span class="hljs-keyword">AND</span> <span class="hljs-number">20</span>;<br></code></pre></td></tr></table></figure>

<p>如需显示不在上面实例范围内的网站，请使用 NOT BETWEEN：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">SELECT</span> <span class="hljs-operator">*</span> <span class="hljs-keyword">FROM</span> Websites<br><span class="hljs-keyword">WHERE</span> alexa <span class="hljs-keyword">NOT</span> <span class="hljs-keyword">BETWEEN</span> <span class="hljs-number">1</span> <span class="hljs-keyword">AND</span> <span class="hljs-number">20</span>;<br></code></pre></td></tr></table></figure>

<p>选取 alexa 介于 1 和 20 之间但 country 不为 USA 和 IND 的所有网站：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">SELECT</span> <span class="hljs-operator">*</span> <span class="hljs-keyword">FROM</span> Websites<br><span class="hljs-keyword">WHERE</span> (alexa <span class="hljs-keyword">BETWEEN</span> <span class="hljs-number">1</span> <span class="hljs-keyword">AND</span> <span class="hljs-number">20</span>)<br><span class="hljs-keyword">AND</span> country <span class="hljs-keyword">NOT</span> <span class="hljs-keyword">IN</span> (<span class="hljs-string">&#x27;USA&#x27;</span>, <span class="hljs-string">&#x27;IND&#x27;</span>);<br></code></pre></td></tr></table></figure>

<p>选取 name 以介于 ‘A’ 和 ‘H’ 之间字母开始的所有网站：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">SELECT</span> <span class="hljs-operator">*</span> <span class="hljs-keyword">FROM</span> Websites<br><span class="hljs-keyword">WHERE</span> name <span class="hljs-keyword">BETWEEN</span> <span class="hljs-string">&#x27;A&#x27;</span> <span class="hljs-keyword">AND</span> <span class="hljs-string">&#x27;H&#x27;</span>;<br></code></pre></td></tr></table></figure>

<p>选取 name 不介于 ‘A’ 和 ‘H’ 之间字母开始的所有网站：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">SELECT</span> <span class="hljs-operator">*</span> <span class="hljs-keyword">FROM</span> Websites<br><span class="hljs-keyword">WHERE</span> name <span class="hljs-keyword">NOT</span> <span class="hljs-keyword">BETWEEN</span> <span class="hljs-string">&#x27;A&#x27;</span> <span class="hljs-keyword">AND</span> <span class="hljs-string">&#x27;H&#x27;</span>;<br></code></pre></td></tr></table></figure>

<p>选取 date 介于 ‘2016-05-10’ 和 ‘2016-05-14’ 之间的所有访问记录：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">SELECT</span> <span class="hljs-operator">*</span> <span class="hljs-keyword">FROM</span> access_log<br><span class="hljs-keyword">WHERE</span> <span class="hljs-type">date</span> <span class="hljs-keyword">BETWEEN</span> <span class="hljs-string">&#x27;2016-05-10&#x27;</span> <span class="hljs-keyword">AND</span> <span class="hljs-string">&#x27;2016-05-14&#x27;</span>;<br></code></pre></td></tr></table></figure>

<h2 id="SQL-别名"><a href="#SQL-别名" class="headerlink" title="SQL 别名"></a>SQL 别名</h2><p>指定了两个别名，一个是 name 列的别名，一个是 country 列的别名。<strong>提示：</strong>如果列名称包含空格，要求使用双引号或方括号：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">SELECT</span> name <span class="hljs-keyword">AS</span> n, country <span class="hljs-keyword">AS</span> c<br><span class="hljs-keyword">FROM</span> Websites;<br></code></pre></td></tr></table></figure>

<p>把三个列（url、alexa 和 country）结合在一起，并创建一个名为 “site_info” 的别名：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">SELECT</span> name, CONCAT(url, <span class="hljs-string">&#x27;, &#x27;</span>, alexa, <span class="hljs-string">&#x27;, &#x27;</span>, country) <span class="hljs-keyword">AS</span> site_info<br><span class="hljs-keyword">FROM</span> Websites;<br></code></pre></td></tr></table></figure>

<p>使用 “Websites” 和 “access_log” 表，并分别为它们指定表别名 “w” 和 “a”（通过使用别名让 SQL 更简短）：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">SELECT</span> w.name, w.url, a.count, a.date<br><span class="hljs-keyword">FROM</span> Websites <span class="hljs-keyword">AS</span> w, access_log <span class="hljs-keyword">AS</span> a<br><span class="hljs-keyword">WHERE</span> a.site_id<span class="hljs-operator">=</span>w.id <span class="hljs-keyword">and</span> w.name<span class="hljs-operator">=</span>&quot;菜鸟教程&quot;;<br></code></pre></td></tr></table></figure>

<p>不带别名的相同的 SQL 语句：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">SELECT</span> Websites.name, Websites.url, access_log.count, access_log.date<br><span class="hljs-keyword">FROM</span> Websites, access_log<br><span class="hljs-keyword">WHERE</span> Websites.id<span class="hljs-operator">=</span>access_log.site_id <span class="hljs-keyword">and</span> Websites.name<span class="hljs-operator">=</span>&quot;菜鸟教程&quot;;<br></code></pre></td></tr></table></figure>

<h2 id="SQL-连接-JOIN"><a href="#SQL-连接-JOIN" class="headerlink" title="SQL 连接(JOIN)"></a>SQL 连接(JOIN)</h2><p>“Websites” 表中的 “<strong>id</strong>“ 列指向 “access_log” 表中的字段 “<strong>site_id</strong>“。上面这两个表是通过 “site_id” 列联系起来的。</p>
<p>然后，如果我们运行下面的 SQL 语句（包含 INNER JOIN）：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">SELECT</span> Websites.id, Websites.name, access_log.count, access_log.date<br><span class="hljs-keyword">FROM</span> Websites<br><span class="hljs-keyword">INNER</span> <span class="hljs-keyword">JOIN</span> access_log<br><span class="hljs-keyword">ON</span> Websites.id<span class="hljs-operator">=</span>access_log.site_id;<br></code></pre></td></tr></table></figure>

<h2 id="SQL-INNER-JOIN-关键字"><a href="#SQL-INNER-JOIN-关键字" class="headerlink" title="SQL INNER JOIN 关键字"></a>SQL INNER JOIN 关键字</h2><p>下面的 SQL 语句将返回所有网站的访问记录：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">SELECT</span> Websites.name, access_log.count, access_log.date<br><span class="hljs-keyword">FROM</span> Websites<br><span class="hljs-keyword">INNER</span> <span class="hljs-keyword">JOIN</span> access_log<br><span class="hljs-keyword">ON</span> Websites.id<span class="hljs-operator">=</span>access_log.site_id<br><span class="hljs-keyword">ORDER</span> <span class="hljs-keyword">BY</span> access_log.count;<br></code></pre></td></tr></table></figure>

<h2 id="SQL-LEFT-JOIN-关键字"><a href="#SQL-LEFT-JOIN-关键字" class="headerlink" title="SQL LEFT JOIN 关键字"></a>SQL LEFT JOIN 关键字</h2><p>下面的 SQL 语句将返回所有网站及他们的访问量（如果有的话）。</p>
<p>以下实例中我们把 Websites 作为左表，access_log 作为右表：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">SELECT</span> Websites.name, access_log.count, access_log.date<br><span class="hljs-keyword">FROM</span> Websites<br><span class="hljs-keyword">LEFT</span> <span class="hljs-keyword">JOIN</span> access_log<br><span class="hljs-keyword">ON</span> Websites.id<span class="hljs-operator">=</span>access_log.site_id<br><span class="hljs-keyword">ORDER</span> <span class="hljs-keyword">BY</span> access_log.count <span class="hljs-keyword">DESC</span>;<br></code></pre></td></tr></table></figure>

<p><strong>注释：</strong>LEFT JOIN 关键字从左表（Websites）返回所有的行，即使右表（access_log）中没有匹配。</p>
<h2 id="SQL-RIGHT-JOIN-关键字"><a href="#SQL-RIGHT-JOIN-关键字" class="headerlink" title="SQL RIGHT JOIN 关键字"></a>SQL RIGHT JOIN 关键字</h2><p>下面的 SQL 语句将返回网站的访问记录。</p>
<p>以下实例中我们把 Websites 作为左表，access_log 作为右表：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">SELECT</span> websites.name, access_log.count, access_log.date<br><span class="hljs-keyword">FROM</span> websites <span class="hljs-keyword">RIGHT</span> <span class="hljs-keyword">JOIN</span> access_log<br><span class="hljs-keyword">ON</span> access_log.site_id<span class="hljs-operator">=</span>websites.id<br><span class="hljs-keyword">ORDER</span> <span class="hljs-keyword">BY</span> access_log.count <span class="hljs-keyword">DESC</span>;<br></code></pre></td></tr></table></figure>

<p><strong>注释：</strong>RIGHT JOIN 关键字从右表（access_log）返回所有的行，即使左表（Websites）中没有匹配。</p>
<h2 id="SQL-FULL-OUTER-JOIN-关键字"><a href="#SQL-FULL-OUTER-JOIN-关键字" class="headerlink" title="SQL FULL OUTER JOIN 关键字"></a>SQL FULL OUTER JOIN 关键字</h2><p>下面的 SQL 语句选取所有网站访问记录。</p>
<p>MySQL中不支持 FULL OUTER JOIN，你可以在 SQL Server 测试以下实例。</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">SELECT</span> Websites.name, access_log.count, access_log.date<br><span class="hljs-keyword">FROM</span> Websites<br><span class="hljs-keyword">FULL</span> <span class="hljs-keyword">OUTER</span> <span class="hljs-keyword">JOIN</span> access_log<br><span class="hljs-keyword">ON</span> Websites.id<span class="hljs-operator">=</span>access_log.site_id<br><span class="hljs-keyword">ORDER</span> <span class="hljs-keyword">BY</span> access_log.count <span class="hljs-keyword">DESC</span>;<br></code></pre></td></tr></table></figure>

<p><strong>注释：</strong>FULL OUTER JOIN 关键字返回左表（Websites）和右表（access_log）中所有的行。如果 “Websites” 表中的行在 “access_log” 中没有匹配或者 “access_log” 表中的行在 “Websites” 表中没有匹配，也会列出这些行。</p>

                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/categories/%E5%90%8E%E7%AB%AF/" class="category-chain-item">后端</a>
  
  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/tags/sql/">#sql</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>sql</div>
      <div>http://example.com/2023/02/25/sql/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>dayu</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2023年2月25日</div>
        </div>
      
      
      
        <div class="license-meta-item">
          <div>许可协议</div>
          <div>
            
              
              
                <a target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
                  <span class="hint--top hint--rounded" aria-label="BY - 署名">
                    <i class="iconfont icon-by"></i>
                  </span>
                </a>
              
            
          </div>
        </div>
      
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2023/09/05/vue3/" title="">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile"></span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2023/02/25/%E5%89%8D%E7%AB%AF%E7%9F%A5%E8%AF%86%E7%82%B9/" title="前端知识点">
                        <span class="hidden-mobile">前端知识点</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
    </div>
  
  
  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.0/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.18.2/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init(Object.assign({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      scrollSmooth    : true,
      includeTitleTags: true,
      headingsOffset  : -boardTop,
    }, CONFIG.toc));
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }

    Fluid.events.registerRefreshCallback(function() {
      if ('tocbot' in window) {
        tocbot.refresh();
        var toc = jQuery('#toc');
        if (toc.length === 0 || !tocbot) {
          return;
        }
        if (toc.find('.toc-list-item').length > 0) {
          toc.css('visibility', 'visible');
        }
      }
    });
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.11/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));

    Fluid.events.registerRefreshCallback(function() {
      if ('anchors' in window) {
        anchors.removeAll();
        var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
        var res = [];
        for (var item of el) {
          res.push('.markdown-body > ' + item.trim());
        }
        if (CONFIG.anchorjs.placement === 'left') {
          anchors.options.class = 'anchorjs-link-left';
        }
        anchors.add(res.join(', '));
      }
    });
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/js/local-search.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
